<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1991-2016 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, with no Front-Cover Texts, and with no
Back-Cover Texts.  A copy of the license is included in the
section entitled "GNU Free Documentation License".
 -->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GNU Binary Utilities: ar scripts</title>

<meta name="description" content="GNU Binary Utilities: ar scripts">
<meta name="keywords" content="GNU Binary Utilities: ar scripts">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Binutils-Index.html#Binutils-Index" rel="index" title="Binutils Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="ar.html#ar" rel="up" title="ar">
<link href="nm.html#nm" rel="next" title="nm">
<link href="ar-cmdline.html#ar-cmdline" rel="prev" title="ar cmdline">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="ar-scripts"></a>
<div class="header">
<p>
Previous: <a href="ar-cmdline.html#ar-cmdline" accesskey="p" rel="prev">ar cmdline</a>, Up: <a href="ar.html#ar" accesskey="u" rel="up">ar</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Binutils-Index.html#Binutils-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Controlling-ar-with-a-Script"></a>
<h3 class="section">1.2 Controlling <code>ar</code> with a Script</h3>

<div class="smallexample">
<pre class="smallexample">ar -M [ &lt;<var>script</var> ]
</pre></div>

<a name="index-MRI-compatibility_002c-ar"></a>
<a name="index-scripts_002c-ar"></a>
<p>If you use the single command-line option &lsquo;<samp>-M</samp>&rsquo; with <code>ar</code>, you
can control its operation with a rudimentary command language.  This
form of <code>ar</code> operates interactively if standard input is coming
directly from a terminal.  During interactive use, <code>ar</code> prompts for
input (the prompt is &lsquo;<samp>AR &gt;</samp>&rsquo;), and continues executing even after
errors.  If you redirect standard input to a script file, no prompts are
issued, and <code>ar</code> abandons execution (with a nonzero exit code)
on any error.
</p>
<p>The <code>ar</code> command language is <em>not</em> designed to be equivalent
to the command-line options; in fact, it provides somewhat less control
over archives.  The only purpose of the command language is to ease the
transition to <small>GNU</small> <code>ar</code> for developers who already have scripts
written for the MRI &ldquo;librarian&rdquo; program.
</p>
<p>The syntax for the <code>ar</code> command language is straightforward:
</p><ul>
<li> commands are recognized in upper or lower case; for example, <code>LIST</code>
is the same as <code>list</code>.  In the following descriptions, commands are
shown in upper case for clarity.

</li><li> a single command may appear on each line; it is the first word on the
line.

</li><li> empty lines are allowed, and have no effect.

</li><li> comments are allowed; text after either of the characters &lsquo;<samp>*</samp>&rsquo;
or &lsquo;<samp>;</samp>&rsquo; is ignored.

</li><li> Whenever you use a list of names as part of the argument to an <code>ar</code>
command, you can separate the individual names with either commas or
blanks.  Commas are shown in the explanations below, for clarity.

</li><li> &lsquo;<samp>+</samp>&rsquo; is used as a line continuation character; if &lsquo;<samp>+</samp>&rsquo; appears
at the end of a line, the text on the following line is considered part
of the current command.
</li></ul>

<p>Here are the commands you can use in <code>ar</code> scripts, or when using
<code>ar</code> interactively.  Three of them have special significance:
</p>
<p><code>OPEN</code> or <code>CREATE</code> specify a <em>current archive</em>, which is
a temporary file required for most of the other commands.
</p>
<p><code>SAVE</code> commits the changes so far specified by the script.  Prior
to <code>SAVE</code>, commands affect only the temporary copy of the current
archive.
</p>
<dl compact="compact">
<dt><code>ADDLIB <var>archive</var></code></dt>
<dt><code>ADDLIB <var>archive</var> (<var>module</var>, <var>module</var>, &hellip; <var>module</var>)</code></dt>
<dd><p>Add all the contents of <var>archive</var> (or, if specified, each named
<var>module</var> from <var>archive</var>) to the current archive.
</p>
<p>Requires prior use of <code>OPEN</code> or <code>CREATE</code>.
</p>
</dd>
<dt><code>ADDMOD <var>member</var>, <var>member</var>, &hellip; <var>member</var></code></dt>
<dd><p>Add each named <var>member</var> as a module in the current archive.
</p>
<p>Requires prior use of <code>OPEN</code> or <code>CREATE</code>.
</p>
</dd>
<dt><code>CLEAR</code></dt>
<dd><p>Discard the contents of the current archive, canceling the effect of
any operations since the last <code>SAVE</code>.  May be executed (with no
effect) even if  no current archive is specified.
</p>
</dd>
<dt><code>CREATE <var>archive</var></code></dt>
<dd><p>Creates an archive, and makes it the current archive (required for many
other commands).  The new archive is created with a temporary name; it
is not actually saved as <var>archive</var> until you use <code>SAVE</code>.
You can overwrite existing archives; similarly, the contents of any
existing file named <var>archive</var> will not be destroyed until <code>SAVE</code>.
</p>
</dd>
<dt><code>DELETE <var>module</var>, <var>module</var>, &hellip; <var>module</var></code></dt>
<dd><p>Delete each listed <var>module</var> from the current archive; equivalent to
&lsquo;<samp>ar -d <var>archive</var> <var>module</var> &hellip; <var>module</var></samp>&rsquo;.
</p>
<p>Requires prior use of <code>OPEN</code> or <code>CREATE</code>.
</p>
</dd>
<dt><code>DIRECTORY <var>archive</var> (<var>module</var>, &hellip; <var>module</var>)</code></dt>
<dt><code>DIRECTORY <var>archive</var> (<var>module</var>, &hellip; <var>module</var>) <var>outputfile</var></code></dt>
<dd><p>List each named <var>module</var> present in <var>archive</var>.  The separate
command <code>VERBOSE</code> specifies the form of the output: when verbose
output is off, output is like that of &lsquo;<samp>ar -t <var>archive</var>
<var>module</var>&hellip;</samp>&rsquo;.  When verbose output is on, the listing is like
&lsquo;<samp>ar -tv <var>archive</var> <var>module</var>&hellip;</samp>&rsquo;.
</p>
<p>Output normally goes to the standard output stream; however, if you
specify <var>outputfile</var> as a final argument, <code>ar</code> directs the
output to that file.
</p>
</dd>
<dt><code>END</code></dt>
<dd><p>Exit from <code>ar</code>, with a <code>0</code> exit code to indicate successful
completion.  This command does not save the output file; if you have
changed the current archive since the last <code>SAVE</code> command, those
changes are lost.
</p>
</dd>
<dt><code>EXTRACT <var>module</var>, <var>module</var>, &hellip; <var>module</var></code></dt>
<dd><p>Extract each named <var>module</var> from the current archive, writing them
into the current directory as separate files.  Equivalent to &lsquo;<samp>ar -x
<var>archive</var> <var>module</var>&hellip;</samp>&rsquo;.
</p>
<p>Requires prior use of <code>OPEN</code> or <code>CREATE</code>.
</p>

</dd>
<dt><code>LIST</code></dt>
<dd><p>Display full contents of the current archive, in &ldquo;verbose&rdquo; style
regardless of the state of <code>VERBOSE</code>.  The effect is like &lsquo;<samp>ar
tv <var>archive</var></samp>&rsquo;.  (This single command is a <small>GNU</small> <code>ar</code>
enhancement, rather than present for MRI compatibility.)
</p>
<p>Requires prior use of <code>OPEN</code> or <code>CREATE</code>.
</p>
</dd>
<dt><code>OPEN <var>archive</var></code></dt>
<dd><p>Opens an existing archive for use as the current archive (required for
many other commands).  Any changes as the result of subsequent commands
will not actually affect <var>archive</var> until you next use <code>SAVE</code>.
</p>
</dd>
<dt><code>REPLACE <var>module</var>, <var>module</var>, &hellip; <var>module</var></code></dt>
<dd><p>In the current archive, replace each existing <var>module</var> (named in
the <code>REPLACE</code> arguments) from files in the current working directory.
To execute this command without errors, both the file, and the module in
the current archive, must exist.
</p>
<p>Requires prior use of <code>OPEN</code> or <code>CREATE</code>.
</p>
</dd>
<dt><code>VERBOSE</code></dt>
<dd><p>Toggle an internal flag governing the output from <code>DIRECTORY</code>.
When the flag is on, <code>DIRECTORY</code> output matches output from
&lsquo;<samp>ar -tv </samp>&rsquo;&hellip;.
</p>
</dd>
<dt><code>SAVE</code></dt>
<dd><p>Commit your changes to the current archive, and actually save it as a
file with the name specified in the last <code>CREATE</code> or <code>OPEN</code>
command.
</p>
<p>Requires prior use of <code>OPEN</code> or <code>CREATE</code>.
</p>
</dd>
</dl>


<hr>
<div class="header">
<p>
Previous: <a href="ar-cmdline.html#ar-cmdline" accesskey="p" rel="prev">ar cmdline</a>, Up: <a href="ar.html#ar" accesskey="u" rel="up">ar</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Binutils-Index.html#Binutils-Index" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
